/*
 * DIM-SUM操作系统 - 内存管理
 *
 * Copyright (C) 2022 国科础石(重庆)软件有限公司
 *
 * 作者: Dong Peng <w-pengdong@kernelsoft.com>
 *
 * License terms: GNU General Public License (GPL) version 3
 *
 */

#ifndef __ASM_MMU_CONTEXT_H
#define __ASM_MMU_CONTEXT_H

#include <asm/memory.h>

extern void *empty_zero_page;

static inline void set_ttbr0(unsigned long ttbr)
{
	//TO_DO
	BUG();
}

static inline void set_sapt(mmu_l1_t* k_l1)
{
	csr_write(sptbr, linear_virt_to_pgnum((virt_addr_t)k_l1) | SATP_MODE);
}

static inline unsigned long read_sapt(void)
{
	return csr_read(sptbr);
}

static inline unsigned long read_sapt_to_vaddr(void)
{
	return (unsigned long)(linear_phys_to_virt(((csr_read(sptbr) & SATP_PPN) << PAGE_SHIFT)));
}


extern u64 idmap_t0sz;

static inline bool __cpu_uses_extended_idmap(void)
{
	return (!IS_ENABLED(CONFIG_ARM64_VA_BITS_48) &&
		unlikely(idmap_t0sz != TCR_T0SZ(VA_BITS)));

	return false;
}

static inline void __cpu_set_tcr_t0sz(u64 t0sz)
{
	//TO_DO
	BUG();
}

static inline void cpu_set_default_tcr_t0sz(void)
{
	__cpu_set_tcr_t0sz(TCR_T0SZ(VA_BITS));
}

#endif /* __ASM_MMU_CONTEXT_H */
